/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;


import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;


import br.com.pascom.vo.Administracao;
import br.com.pascom.vo.AgendaParoquial;
import br.com.pascom.vo.Comunidade;
import br.com.pascom.vo.DadosParoquial;
import br.com.pascom.vo.Evento;
import br.com.pascom.vo.Galeria;
import br.com.pascom.vo.HistoriaPadroeira;
import br.com.pascom.vo.HistoriaParoquia;
import br.com.pascom.vo.Horario;
import br.com.pascom.vo.Noticia;
import br.com.pascom.vo.Paroco;
import br.com.pascom.vo.Pastoral;
import br.com.pascom.vo.SantosDoDia;
import br.com.pascom.vo.Telefone;

public class HibernateUtil {

    private static SessionFactory sessionFactory;

    private HibernateUtil() {
        
    }

    public static SessionFactory getSessionFactory() {

        if (sessionFactory == null) {
            try {
                // Create the SessionFactory from standard (hibernate.cfg.xml)
                // config file.
                AnnotationConfiguration ac = new AnnotationConfiguration();
                
                ac.addAnnotatedClass(Administracao.class);
                ac.addAnnotatedClass(AgendaParoquial.class);
                ac.addAnnotatedClass(Comunidade.class);
                ac.addAnnotatedClass(DadosParoquial.class);
                ac.addAnnotatedClass(Evento.class);
                ac.addAnnotatedClass(Galeria.class);
                ac.addAnnotatedClass(HistoriaPadroeira.class);
                ac.addAnnotatedClass(HistoriaParoquia.class);
                ac.addAnnotatedClass(Horario.class);
                ac.addAnnotatedClass(Noticia.class);
                ac.addAnnotatedClass(Paroco.class);
                ac.addAnnotatedClass(Pastoral.class);
                ac.addAnnotatedClass(SantosDoDia.class);
                ac.addAnnotatedClass(Telefone.class);
                
                sessionFactory = ac.configure().buildSessionFactory();
                //SchemaExport se = new SchemaExport(ac);
                //se.create(true, true);
                

            } catch (Throwable ex) {
                // Log the exception.
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }

            return sessionFactory;

        } else {
            return sessionFactory;
        }
        
    }

    public static void main(String[] args) {
        HibernateUtil.getSessionFactory();
    }

}
